<!--
 * @Author: wanglidong
 * @Date: 2021-04-08 09:23:01
 * @LastEditTime: 2022-07-04 17:21:21
 * @LastEditors: wanglidong
 * @Description:
 * @FilePath: \lowcode-front\src\views\investment\monthlyreport\monthlyreport-detail.vue
 * @nbsg
-->
<template>
  <div class="pre-archive-detail">
    <el-dialog width="70%" class="WholeScroll" :visible.sync="formShow" @close="handleClickDeal('cancel')" v-dialog-drag :modal-append-to-body="false" :close-on-click-modal="false">
      <span slot="title">
        <i class="iconfont icon-a-qushitiaoxingtu-08"></i>
        <span>{{ title }}</span>
      </span>
      <div class="WholeScroll" style="max-height: 650px; overflow: auto;padding-right:10px;">
        <el-form :model="formBaseData" ref="formBaseData" :rules="formBaseRules" style="position: relative">
          <el-tabs v-model="activeName">
            <el-tab-pane label="基本信息" name="first">
              <el-row>
                <el-col :span="12">
                  <el-form-item label="公司" prop="companyId" :label-width="formlabelWidth">
                    <el-select class="select" v-on:change="getProjectByCompanyId()" value-key="id" v-model="formBaseData.companyId" placeholder="选择公司" style="width: 100%" clearable :disabled="detailType != 'build' ">
                      <el-option v-for="item in companyTree" :key="item.id" :label="item.name" :value="item.id">
                      </el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="项目" prop="projectId" :label-width="formlabelWidth">
                    <el-select class="select" v-on:change="getProjectChange()" style="width: 100%" value-key="id" v-model="formBaseData.projectId" placeholder="选择项目" clearable :disabled="detailType != 'build' ">
                      <el-option v-for="item in projectTree" :key="item.id" :label="item.name" :value="item.id">
                      </el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
              </el-row>

              <el-row>
                <el-col :span="12">
                  <el-form-item label="月份" prop="month" :label-width="formlabelWidth">
                    <el-date-picker v-model="formBaseData.month" :disabled="detailType != 'build'" style="width: 100%;" type="month" :clearable="false" :picker-options="pickerOptions" value-format="yyyy-MM" @change="chooseDatePicker" placeholder="选择日期">
                    </el-date-picker>
                  </el-form-item>
                </el-col>
              </el-row>

              <el-row>
                <el-col :span="12">
                  <el-form-item label="项目总投资" prop="totalInvestment" :label-width="formlabelWidth">
                    <el-input v-model="formBaseData.totalInvestment" @keyup.native="newUpNumber" @keydown.native="newUpNumber" disabled>
                      <template slot="append">万元</template>
                    </el-input>
                  </el-form-item>
                </el-col>

                <el-col :span="12">
                  <el-form-item label="截止本月累计投资" prop="accumulatedInvestment" :label-width="formlabelWidth">
                    <el-input v-model="formBaseData.accumulatedInvestment" @keyup.native="newUpNumber" @keydown.native="newUpNumber" :disabled="detailType != 'build' ">
                      <template slot="append">万元</template>
                    </el-input>
                  </el-form-item>
                </el-col>
              </el-row>

              <el-row>
                <el-col :span="24">
                  <el-form-item label="备注" :label-width="formlabelWidth">
                    <el-input type="textarea" :rows="4" placeholder="请输入备注" v-model="formBaseData.remark" :disabled="detailType === 'check'"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>

              <el-row>
                <div class="design-middle-box">
                  <div class="left-box">
                    <p :class="chooseIndex == index?'chooseText':''" v-for="(item,index) in leftArr" :key="index" @click="chooseIndex = index">{{item.name}}</p>
                  </div>
                  <div class="right-box WholeScroll">
                    <div v-show="chooseIndex == 0">
                      <el-row>
                        <el-col :span="24">
                          <el-col :span="12">
                            <el-form-item :label="`${chooseDateData.year}年计划投资额`" prop="planinvestmentYear" :label-width="formlabelWidthTwo">
                              <el-input v-model="formBaseData.planinvestmentYear" @keyup.native="newUpNumber" @keydown.native="newUpNumber" :disabled="detailType === 'check'">
                                <template slot="append">万元</template>
                              </el-input>
                            </el-form-item>
                          </el-col>

                          <!-- <el-col :span="12">
                            <el-form-item
                              :label="`${chooseDateData.year}年累计完成投资额`"
                              prop="completinvestmentYear"
                              :label-width="formlabelWidthTwo"
                            >
                              <el-input v-model="formBaseData.completinvestmentYear"
                                        @keyup.native="newUpNumber" @keydown.native="newUpNumber"
                                        disabled >
                                <template slot="append">万元</template>
                              </el-input>
                            </el-form-item>
                          </el-col> -->
                          <el-col :span="12">
                            <el-form-item :label="`${chooseDateData.year}年${parseInt(chooseDateData.month) > 6?'下半年':'上半年'}计划投资额`" prop="planinvestmentHalfYear" :label-width="formlabelWidthTwo">
                              <el-input v-model="formBaseData.planinvestmentHalfYear" @keyup.native="newUpNumber" @keydown.native="newUpNumber" :disabled="detailType === 'check'">
                                <template slot="append">万元</template>
                              </el-input>
                            </el-form-item>
                          </el-col>
                        </el-col>
                      </el-row>

                      <el-row>
                        <el-col :span="24">

                          <!-- <el-col :span="12">
                            <el-form-item
                              label="半年累计完成投资额"
                              prop="completinvestmentHalfYear"
                              :label-width="formlabelWidthTwo"
                            >
                              <el-input v-model="formBaseData.completinvestmentHalfYear"
                                        @keyup.native="newUpNumber" @keydown.native="newUpNumber" disabled >
                                <template slot="append">万元</template>
                              </el-input>
                            </el-form-item>
                          </el-col> -->
                        </el-col>
                      </el-row>

                      <el-row>
                        <el-col :span="24">
                          <!-- <el-col :span="12">
                            <el-form-item
                              :label="`${chooseDateData.year}年${chooseDateData.month}月计划投资额`"
                              prop="planinvestmentMonth"
                              :label-width="formlabelWidthTwo"
                            >
                              <el-input v-model="formBaseData.planinvestmentMonth"
                                        @keyup.native="newUpNumber" @keydown.native="newUpNumber"
                                         >
                                <template slot="append">万元</template>
                              </el-input>
                            </el-form-item>
                          </el-col> -->
                          <el-col :span="12">
                            <el-form-item :label="`${chooseDateData.year}年${chooseDateData.month}月完成投资额`" prop="investmentcompletMonth" :label-width="formlabelWidthTwo">
                              <el-input v-model="formBaseData.investmentcompletMonth" v-on:change="investmentcompletMonthChange()" @keyup.native="newUpNumber" @keydown.native="newUpNumber" :disabled="detailType === 'check'">
                                <template slot="append">万元</template>
                              </el-input>
                            </el-form-item>
                          </el-col>
                          <el-col :span="12">
                            <el-form-item label="下月计划投资" prop="planinvestmentNextMonth" :label-width="formlabelWidthTwo">
                              <el-input v-model="formBaseData.planinvestmentNextMonth" @keyup.native="newUpNumber" @keydown.native="newUpNumber" :disabled="detailType === 'check'">
                                <template slot="append">万元</template>
                              </el-input>
                            </el-form-item>
                          </el-col>
                        </el-col>
                      </el-row>

                      <el-row>
                        <el-col :span="24">

                        </el-col>
                      </el-row>

                    </div>
                    <div v-show="chooseIndex == 1">
                      <el-row>
                        <el-col :span="24">
                          <el-col :span="12">
                            <el-form-item :label="`2022年完成投资额`" prop="investmentcompletedBeforyear4" :label-width="formlabelWidthTwo">
                              <el-input v-model="formBaseData.investmentcompletedBeforyear4" @keyup.native="newUpNumber" @keydown.native="newUpNumber" v-on:change="oldYearChange()" :disabled="detailType === 'check'">
                                <template slot="append">万元</template>
                              </el-input>
                            </el-form-item>
                          </el-col>
                          <el-col :span="12">
                            <el-form-item :label="`2021年完成投资额`" prop="investmentcompletedBeforyear3" :label-width="formlabelWidthTwo">
                              <el-input v-model="formBaseData.investmentcompletedBeforyear3" @keyup.native="newUpNumber" @keydown.native="newUpNumber" v-on:change="oldYearChange()" :disabled="detailType === 'check'">
                                <template slot="append">万元</template>
                              </el-input>
                            </el-form-item>
                          </el-col>
                        </el-col>
                      </el-row>
                      <el-row>
                        <el-col :span="24">
                          <el-col :span="12">
                            <el-form-item :label="`2020年完成投资额`" prop="investmentcompletedBeforyear2" :label-width="formlabelWidthTwo">
                              <el-input v-model="formBaseData.investmentcompletedBeforyear2" @keyup.native="newUpNumber" @keydown.native="newUpNumber" v-on:change="oldYearChange()" :disabled="detailType === 'check'">
                                <template slot="append">万元</template>
                              </el-input>
                            </el-form-item>
                          </el-col>
                        </el-col>
                      </el-row>
                    </div>
                  </div>
                </div>
              </el-row>
            </el-tab-pane>
          </el-tabs>
        </el-form>
      </div>
      <div slot="footer" class="dialog-footer">
        <!--api操作按钮 除去上报-->
        <!--新建和编辑的暂存上报-->
        <!--:loading="isLoading" -->
        <template v-if="detailType === 'build' || detailType === 'edit'">
          <el-button size="small" type="primary" :loading="isLoading" @click="checkDateAndProject"><i class="iconfont icon-icon_save"></i> 确 定
          </el-button>
        </template>
        <el-button size="small" @click="handleClickDeal('cancel')"><i class="iconfont icon-icon_cancel"></i> 取 消
        </el-button>
      </div>

    </el-dialog>

  </div>
</template>

<script>
import { v4 as uuidv4 } from 'uuid';


import msgUtil from '@/utils/msgUtil'
// import crudProject from '@/api/buss/project'
// import payment from '@/api/buss/contractPayment'
// import designStimate from '@/api/buss/designStimate'
// import WfProcess from '@/components/WorkFlow/process/index'
import projectSectionInfo from '@/api/buss/common'
import startMixin from '@/mixins/wfStartMixin'
import approveMixin from '@/mixins/wfApproveMixin'
import PopBtn from '@/components/ExtBpmn/Btn/index'
import BpmnForm from '@/components/ExtBpmn/ExtForm/bpmn-form'

const PREVIEW_URL = process.env.VUE_APP_FILE_PREVIEW
export default {
  name: 'monthlyreport-detail',
  props: {
    postDetail: {
      type: Object,
      default: {
        show: false,
        type: 'build',
        params: {}
      },
    },
  },
  watch: {
    postDetail(value) {
      // 显示详情弹窗
      this.formShow = value.show
      // 初始化窗口参数
      this.activeName = 'first'
      // 详情类型
      this.detailType = value.type

      if (this.detailType == 'build') {
        this.title = '新增月报表'
        this.showBpmnForm = true
        this.formBaseData.month = this.formateDate(new Date())
      } else if (this.detailType == 'check') {
        this.title = '查看月报表'
      } else if (this.detailType == 'edit') {
        this.title = '编辑月报表'
        this.showBpmnForm = true
      }
      else if (this.detailType == 'approve') {
        this.title = '月报表'
        this.showBpmnForm = true
      } else {
        this.title = ''
      }

      // 详情id
      // this.detailId = value.detailId?value.detailId:'';
      this.detailId = value.params === undefined ? '0' : value.params.detailId
      if (this.detailType != 'build') {
        // 获取详情请求
        this.getProjectSectionInfoTree();
        this.getDetail()
      } else {
        this.getProjectSectionInfoTree();
      }
    }
  },
  data() {
    return {
      chooseDateData: {
        year: '',
        month: ''
      },
      halfYearStar: '',
      year: '',
      dateArray: [],
      choseData: '', // 初始化选择日期
      chooseYear: new Date().getFullYear(),
      showChooseDateDialog: false,
      leftArrValue: 0,
      dialogVisible: false,
      videoUrl: '',
      showConsultUnit: true,
      companyTree: [], // 公司下拉
      projectTree: [], // 项目下拉
      showBpmnForm: false,

      qjbywctz: 0, // 定义一个全局的本月完成投资
      nowYearMoney: 0, // 定义一个全局的本年完成投资

      isLoading: false,
      detailType: 'build', // 详情类型 build新建 check不可编辑查看 edit编辑
      detailId: '', // 当前详情的id
      formShow: false, // 表单展示
      formlabelWidth: '150px', // 表单左侧标题宽度
      formlabelWidthTwo: '220px', // 表单左侧标题宽度
      formlabelWidthThree: '150px', // 表单左侧标题宽度
      formlabelWidthFore: '100px', // 表单左侧标题宽度
      formlabelWidthFive: '180px', // 表单左侧标题宽度
      title: '',
      activeName: 'first',
      pickerOptions: {
        disabledDate: (time) => {
          if (this.dateArray.includes(this.getLocalTime(time.getTime()))) {
            return true
          }
          if (time.getTime() > Date.now() - 8.64e6) {
            return true
          }
          var date = new Date(time.getTime());
          if (date.getFullYear() < 2023) {
            return true
          }
        }
      },
      chooseIndex: 0,
      leftArr: [
        {
          name: '本年'
        },
        {
          name: '历年'
        }
      ],

      fileListArr: [],
      fileSystem: {
        'one': {
          sys: 'buss',
          module: 'monthlyreport',
          part: 'one',
          compoName: 'fileOne'
        }
      },

      selectList: {
        isConsultUnit: [{
          name: '是',
          value: 1
        }, {
          name: '否',
          value: 0
        }],
        //所有合同
        projectArr: [],
        companyList: [],
        file: []
      }, // 所有下拉框列表的集合
      afterAmount: '',
      addAmount: '',
      flag: false,

      formBaseData: {
        id: '',
        companyId: '',
        projectId: '',
        month: '',
        totalInvestment: '', // 总投资额
        accumulatedInvestment: '', // 截止本月累计投资
        planinvestmentYear: '', // 本年计划投资额
        completinvestmentYear: '', // 本年累计完成投资额
        planinvestmentHalfYear: '', // 上下半年计划投资额
        completinvestmentHalfYear: '', // 上下半年累计完成投资额
        planinvestmentMonth: '',// 本月计划
        investmentcompletMonth: '',// 本月完成
        planinvestmentNextMonth: '', // 下月计划
        investmentcompletedBeforyear1: '',// 历年1
        investmentcompletedBeforyear2: '',// 历年2
        investmentcompletedBeforyear3: '',// 历年3
        investmentcompletedBeforyear4: '',// 历年4
        remark: '',
      }, // 表单基本信息内容
      variables: { needReview: '0' },
      //  允许选择部门
      enableDept: false,
      formBaseRules: {
        companyId: [
          {
            required: true,
            message: '请选择公司',
            trigger: 'blur'
          }
        ],
        projectId: [
          {
            required: true,
            message: '请选择项目',
            trigger: 'blur'
          }
        ],
        month: [
          {
            required: true,
            message: '请选择月份',
            trigger: 'blur'
          }
        ],
        planinvestmentYear: [
          {
            required: true,
            message: '请输入当年计划投资额',
            trigger: 'blur'
          }
        ],

        planinvestmentHalfYear: [
          {
            required: true,
            message: '请输入（上下）半年计划投资额',
            trigger: 'blur'
          }
        ],

        investmentcompletMonth: [
          {
            required: true,
            message: '请输入本月完成投资额',
            trigger: 'blur'
          }
        ],

        planinvestmentNextMonth: [
          {
            required: true,
            message: '请输入下月计划投资额度',
            trigger: 'blur'
          }
        ],


      } // 表单基本信息验证
    }
  },

  created() {
  },
  methods: {
    formateDate(value) {
      let date = new Date(value)
      let y = date.getFullYear()
      let m = date.getMonth() + 1

      // 修改月份格式
      if (m >= 1 && m <= 9) {
        m = '0' + m
      }
      let currentFormatDate = y + '-' + m
      return currentFormatDate
    },
    // 公司下拉
    getProjectSectionInfoTree() {
      return projectSectionInfo.getProjectSectionInfoTree().then(res => {
        if (res.code === 200) {
          var data = res.data;
          this.companyTree = data;
          if (this.companyTree.length > 0) {
            if (this.detailType == 'build') {
              this.formBaseData.companyId = this.companyTree[0].id;
            }
          }
          this.getProjectByCompanyId();
          /*return new Promise(reslove=>{
            reslove(res)
          })*/
        } else {
          msgUtil.error2(res.data.message)
        }
      })
    },

    /**
     * 项目变更时 获取已经存在的日期
     */
    getProjectChange() {
      this.formBaseData.totalInvestment = '';
      if (!this.formBaseData.projectId) {
        return;
      }
      if (this.detailType == 'build') {
        this.chooseDatePicker(this.formBaseData.month)
      }
      // 获取项目投资总额
      let postData = {
        projectId: this.formBaseData.projectId
      }
      this.$httpPost('buss/monthlyreport/getTotalProjectAmountById', postData).then(res => {
        if (res.code == 200) {
          this.formBaseData.totalInvestment = res.data;
        } else {
          this.$messageError(res.message);
        }
      }).catch(e => {
        console.log(e);
      })
      /* if(this.detailType =='build'){
         this.getBaseDateByProjectAndMonth();
       }*/


    },


    // 本月完成投资值改变事件
    investmentcompletMonthChange() {
      let bywctz = 0;
      let jzbyljwctz = 0; // 截至本月累计
      let bennljwctz = 0; // 本年累计
      let bannljwctz = 0; // 半年累计


      let qjBywctz = 0;
      if (this.qjbywctz) {
        qjBywctz = Number(this.qjbywctz);
      } else {
        qjBywctz = 0;
      }

      // 截至本月累计
      if (this.formBaseData.accumulatedInvestment) {
        jzbyljwctz = Number(this.formBaseData.accumulatedInvestment);
      }

      // 本年累计
      if (this.formBaseData.completinvestmentYear) {
        bennljwctz = Number(this.formBaseData.completinvestmentYear);
      }

      // 半年累计
      if (this.formBaseData.completinvestmentHalfYear) {
        bannljwctz = Number(this.formBaseData.completinvestmentHalfYear);
      }


      // 本月完成
      if (this.formBaseData.investmentcompletMonth) {
        bywctz = Number(this.formBaseData.investmentcompletMonth);
      }


      jzbyljwctz = jzbyljwctz - qjBywctz + bywctz;
      bennljwctz = bennljwctz - qjBywctz + bywctz;
      bannljwctz = bannljwctz - qjBywctz + bywctz;

      this.formBaseData.accumulatedInvestment = jzbyljwctz;
      this.formBaseData.completinvestmentYear = bennljwctz;
      this.formBaseData.completinvestmentHalfYear = bannljwctz;
      this.nowYearMoney = this.nowYearMoney - qjBywctz + bywctz;

      if (this.formBaseData.investmentcompletMonth) {
        this.qjbywctz = this.formBaseData.investmentcompletMonth;
      } else {
        this.qjbywctz = 0;
      }


    },
    // 历年完成投资值改变事件
    oldYearChange() {
      this.formBaseData.accumulatedInvestment = (this.nowYearMoney + Number(this.formBaseData.investmentcompletedBeforyear2)
        + Number(this.formBaseData.investmentcompletedBeforyear3) + Number(this.formBaseData.investmentcompletedBeforyear4))
    },

    // 月份改变事件
    chooseDatePicker(val) {
      console.log(val)
      this.$set(this.chooseDateData, 'year', val.split('-')[0])
      this.$set(this.chooseDateData, 'month', val.split('-')[1])
      this.leftArr[0].name = String(this.chooseDateData.year) + '年'
      // this.chooseYear = new Date(val).getFullYear()
      // 初始化数据
      this.getBaseDateByProjectAndMonth();
    },


    // 项目和月份改变时 获取基础数据
    getBaseDateByProjectAndMonth() {
      if (!this.formBaseData.month) {
        return
      }
      if (!this.formBaseData.projectId) {
        return
      }

      // 获取项目投资总额
      let postData = {
        projectId: this.formBaseData.projectId,
        month: this.formBaseData.month,
      }
      this.$httpPost('buss/monthlyreport/getBaseMonthlyReportVO', postData).then(res => {
        if (res.code == 200) {
          this.formBaseData.accumulatedInvestment = res.data.accumulatedInvestment;

          this.formBaseData.planinvestmentYear = res.data.planinvestmentYear;// 当年计划投资
          this.formBaseData.completinvestmentYear = res.data.completinvestmentYear;// 当年累计完成投资
          this.formBaseData.planinvestmentHalfYear = res.data.planinvestmentHalfYear;// 当年半年计划投资
          this.formBaseData.completinvestmentHalfYear = res.data.completinvestmentHalfYear;// 当年累计投资
          this.formBaseData.planinvestmentMonth = res.data.planinvestmentMonth;// 本月计划投资额
          this.formBaseData.planinvestmentNextMonth = res.data.planinvestmentNextMonth;// 本月计划投资额
          this.formBaseData.investmentcompletMonth = res.data.investmentcompletMonth;// 本月计划投资额
          // 历年的3个
          this.formBaseData.investmentcompletedBeforyear2 = res.data.investmentcompletedBeforyear2;
          this.formBaseData.investmentcompletedBeforyear3 = res.data.investmentcompletedBeforyear3;
          this.formBaseData.investmentcompletedBeforyear4 = res.data.investmentcompletedBeforyear4;
          this.nowYearMoney = this.formBaseData.accumulatedInvestment - this.formBaseData.investmentcompletedBeforyear2
            - this.formBaseData.investmentcompletedBeforyear3 - this.formBaseData.investmentcompletedBeforyear4
        } else {
          this.$messageError(res.message);
        }
      }).catch(e => {
        console.log(e);
      })
    },
    uuid() {
      return uuidv4().split('-')[0]
    },
    uploadFile(file, row) {
      console.log(file, row)
      //配置一下上传的参数
      row.loading = true
      this.$publicUpload.uploadFile(
        file,
        this.uuid(),
        'monthlyreport',
        'file1',
        file.name,
      ).then(res => {
        //成功的回调，往row里面塞fileName
        if (!row.fileList) {
          row.fileList = []
        }
        let arr = JSON.parse(JSON.stringify(row.fileList))
        arr.push({
          name: file.name,
          size: file.size,
          id: res.data[0],
          isLoading: false,
        })
        row.loading = false
        this.$set(row, 'fileList', arr)
        this.$forceUpdate()
        console.log(row.fileList, 'row.fileListrow.fileListrow.fileListrow.fileList')
      }).catch(res => {

      })
    },

    getLocalTime(ns) {
      let date = new Date(ns);
      let year = date.getFullYear()
      let month = date.getMonth() + 1;
      let day = date.getDate()
      month = month < 10 ? '0' + month : month;
      day = day < 10 ? '0' + day : day;
      date = year + '-' + month + '-' + day;
      return date
    },
    /**
     *  根据建设单位查询下面的所有项目
     * */
    getProjectByCompanyId() {
      if (this.formBaseData.companyId) {
        this.companyTree.forEach((item) => {
          if (item.id === this.formBaseData.companyId) {
            this.projectTree = item.children
            if (this.detailType == 'build') {
              this.formBaseData.projectId = this.projectTree[0].id;
              this.getProjectChange();
            }
          }
        })
      }
    },



    // 获取详情请求 api
    getDetail() {
      let id = this.detailId;
      // designStimate.getOne(this.detailId).then(res => {
      this.$httpGet('buss/monthlyreport/getOne?id=' + id).then(res => {
        if (res.code == 200) {
          let data = res.data
          this.formBaseData = data
          if (this.formBaseData.companyId) {
            this.getProjectByCompanyId();
          }
          this.$set(this.chooseDateData, 'year', this.formBaseData.month.split('-')[0])
          this.$set(this.chooseDateData, 'month', this.formBaseData.month.split('-')[1])
          this.qjbywctz = this.formBaseData.investmentcompletMonth;
          this.nowYearMoney = this.formBaseData.investmentcompletMonth - this.formBaseData.investmentcompletedBeforyear2
            - this.formBaseData.investmentcompletedBeforyear3 - this.formBaseData.investmentcompletedBeforyear4
          this.$forceUpdate()
          // this.formBaseData = res.data
        } else {
          msgUtil.error2(res.data.message)
        }
      }).catch((res) => {
        console.log(res)
        msgUtil.error2("获取详情信息失败")
      })

    },




    // 提交详情 提交1/暂存0 新建0/修改1
    submitDetail(type, callback) {
      let submit = 'buss/monthlyreport/submit'
      let resubmit = 'buss/monthlyreport/resubmit'
      let url = this.detailType == 'build' ? submit : resubmit

      // this.formBaseData.imageProgressDailyInfoList = this.imageProgressInfoList
      // this.isLoading = true

      return this.$httpPost(url, this.formBaseData).then(res => {
        if (res.code == 200) {
          // this.formBaseData.id = res.data.data;
          this.detailId = res.data
          // this.saveFiles()
          this.$messageSuccess("保存成功")
        } else {
          this.$messageError(res.message);
        }
        if (callback) callback();
      }).catch(e => {
        console.log(e);
        this.$messageError("请求保存数据失败")
      })
    },

    // 检测项目和日期 新增时判断 一个项目 一个日期只能新增一条
    checkDateAndProject() {

      if (this.detailType == 'edit') {
        this.handleClickDeal('submit', { flag: 1 })
      } else {
        // 新增 需要校验
        let postData = {
          projectId: this.formBaseData.projectId,
          month: this.formBaseData.month
        }
        this.$httpPost('buss/monthlyreport/checkByProjectAndData', postData).then(res => {
          if (res.code == 200) {
            // this.formBaseData.id = res.data.data;
            if (res.data == '2') {
              this.$message.custom('warning', '当前月份数据已经存在 不允许新增多条')
            } else {
              // 新增
              this.handleClickDeal('submit', { flag: 1 })
            }

          } else {
            this.$messageError(res.message);
          }
        }).catch(e => {
          console.log(e);
        })
      }
    },

    // 点击各个流程的按钮事件
    handleClickDeal(type, res, callback) {
      switch (type) {
        // 取消，关闭窗口
        case 'cancel':
          // 重置表单验证
          console.log(this.activeName)
          if (this.$refs['formBaseData']) {
            this.$refs['formBaseData'].resetFields()
          }
          this.qjbywctz = 0;
          this.nowYearMoney = 0;
          this.formBaseData = {
            id: '',
            companyId: '',
            projectId: '',
            month: '',
            totalInvestment: '', // 总投资额
            accumulatedInvestment: '', // 截止本月累计投资
            planinvestmentYear: '', // 本年计划投资额
            completinvestmentYear: '', // 本年累计完成投资额
            planinvestmentHalfYear: '', // 上下半年计划投资额
            completinvestmentHalfYear: '', // 上下半年累计完成投资额
            planinvestmentMonth: '',// 本月计划
            investmentcompletMonth: '',// 本月完成
            planinvestmentNextMonth: '', // 下月计划
            investmentcompletedBeforyear1: '',// 历年1
            investmentcompletedBeforyear2: '',// 历年2
            investmentcompletedBeforyear3: '',// 历年3
            investmentcompletedBeforyear4: '',// 历年4
            remark: '',
          }
          this.variables = {}
          this.flag = false
          //提交按钮清空
          this.showAuditBtn = false
          // 清空文件
          this.leftArr = [
            {
              name: '本年'
            },
            {
              name: '历年'
            }
          ]
          this.selectList.file = []
          this.buildUnitTable = [],
            this.selectList = {},
            this.showConsultUnit = true,
            this.companyTree = [], // 公司下拉
            this.projectTree = [], // 项目下拉
            this.showBpmnForm = false
          this.detailId = ''
          this.selectList = {
            isConsultUnit: [{
              name: '是',
              value: 1
            }, {
              name: '否',
              value: 0
            }],
            //所有合同
            projectArr: [],
            companyList: [],
            file: []
          },
            // 清空文件
            // 关闭弹窗
            this.formShow = false
          break
        // 保存
        case 'submit':
          let flag = res.flag

          // 验证文件
          /* if (!this.checkoutFile()) {
             this.isLoading = false
             return
           }*/
          // 表单验证
          this.$refs['formBaseData'].validate((valid) => {
            if (valid) {
              // this.isLoading = true
              // 提交详情
              this.submitDetail(flag, () => {

                this.$emit('reloadList')
                this.formShow = false
              }).finally(() => {
                callback && callback();
              })
            } else {
              callback && callback();
            }
          })
          break

      }
    },


    saveFiles() {
      this.$refs['fileOne'].saveAll(this.detailId)
    },


    tableChange(val) {
      this.$set(this, 'buildUnitTable', [...val])
    },


    cancel() {
      this.handleClickDeal('cancel')
    },
    onSave(_, callback) {

      this.handleClickDeal('submit', { flag: 1 }, callback)
    },
    onComplete(data) {

    },


    fetchData() {
      this.$emit('reloadList')
      this.formShow = false
    },
    removeFile(file, fileList) {
      fileList.forEach((item, index) => {
        if (file.id === item.id) {
          fileList.splice(index, 1)
        }
      })
      this.$publicUpload.removeFile(file.id)
    },
    newUpNumber() {
      var obj = event.target;
      var t = obj.value.charAt(0);
      obj.value = obj.value.replace(".", "$#$")//把第一个字符'.'替换成'$#$'
        .replace(/\./g, "")//把其余的字符'.'替换为空
        .replace("$#$", ".")//把字符'$#$'替换回原来的'.'
        .replace(/[^\d.]/g, "")//只能输入数字和'.'
        .replace(/^\./g, "")//不能以'.'开头
      // .replace( /([0-9]+\.[0-9]{2})[0-9]*/,"$1")//只保留2位小数
      if (t == '-') {
        obj.value = '-' + obj.value;
      }
    },
    newUpNumber_2() {
      var obj = event.target;
      var t = obj.value.charAt(0);
      obj.value = obj.value.replace(".", "$#$")//把第一个字符'.'替换成'$#$'
        .replace(/\./g, "")//把其余的字符'.'替换为空
        .replace("$#$", ".")//把字符'$#$'替换回原来的'.'
        .replace(/[^\d]/g, '')//只能输入数字和'.'
        .replace(/^\./g, "")//不能以'.'开头
      // .replace( /([0-9]+\.[0-9]{2})[0-9]*/,"$1")//只保留2位小数
      if (t == '-') {
        obj.value = '-' + obj.value;
      }
    },
  }
}
</script>

<style scoped lang="scss">
$borderColor: #c0c4cc;
.contract-ele {
  width: 100%;
}

.contract-ele-long {
  width: 280px;
  width: 98%;
}

.el-input .el-select {
  width: 130px;
}

.formTitle {
  font-weight: bold;
  font-size: 16px;
}

.hoverTxt {
  color: #008fe0;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.design-middle-box {
  border: 1px $borderColor solid;
  display: flex;
  flex-direction: row;
  .left-box {
    min-width: 200px;
    padding: 15px;
    border-right: 1px $borderColor solid;
    p {
      cursor: pointer;
    }
  }
  .right-box {
    flex-grow: 1;
    padding: 15px;
  }
  .chooseText {
    color: #008fe0;
  }
}
.actionWidth {
  div:nth-child(1) {
    display: inline-block;
  }
}
.fileText {
  cursor: pointer;
  margin: 0;
  padding-left: 10px;
  display: flex;
  align-items: center;
  img {
    height: 20px;
    margin-right: 15px;
  }
  span {
    width: 160px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    word-break: keep-all;
    margin-right: 15px;
  }
}
.fileText:hover {
  background-color: rgb(245, 247, 250);
}
.blueText {
  color: #0c8bff;
  margin-left: 15px;
  cursor: pointer;
}
</style>
<style lang="scss">
.dateRed span {
  border: 1px solid #29b2f5;
  border-radius: 50%;
}
</style>
